package com.hyk.commonLib.common.drawable;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;

import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.hyk.commonLib.common.utils.ResUtils;


/**
 * Created by 贺玉琨 on 2019/3/7.
 */

public class DividerDrawable extends Drawable {

    private final Paint paint;
    private int height = 1;
    private int width = 1;

    public DividerDrawable() {
        this(Color.parseColor("#dedede"));
    }

    public DividerDrawable(@ColorInt int color) {
        this.paint = new Paint();
        paint.setColor(color);
    }

    public DividerDrawable setColor(@ColorInt int color) {
        paint.setColor(color);
        return this;
    }

    public DividerDrawable setColorRes(@ColorRes int color) {
        paint.setColor(ResUtils.getColor(color));
        return this;
    }

    @Override
    public void draw(@NonNull Canvas canvas) {
        canvas.drawRect(getBounds().left, getBounds().top, getBounds().right, getBounds().bottom, paint);
    }

    public DividerDrawable setHeight(int height) {
        this.height = height;
        return this;
    }

    public DividerDrawable setWidth(int width) {
        this.width = width;
        return this;
    }

    @Override
    public int getIntrinsicHeight() {
        return height;
    }

    @Override
    public int getIntrinsicWidth() {
        return width;
    }

    @Override
    public void setAlpha(@IntRange(from = 0, to = 255) int i) {

    }

    @Override
    public void setColorFilter(@Nullable ColorFilter colorFilter) {

    }

    @Override
    public int getOpacity() {
        return PixelFormat.UNKNOWN;
    }
}
